﻿// MIT License
// 开源地址：https://gitee.com/co1024/AbcMvc
// Copyright (c) 2021-2022 1024
// Abc.Mvc=Furion+EF+SqlSugar+Pear layui admin.

namespace Abc.Base;

/// <summary>
/// 登陆失败对象
/// </summary>
public class LoginFailDto
{
    public LoginFailDto()
    {
    }

    /// <summary>
    /// 构造函数
    /// </summary>
    /// <param name="account">登陆账号</param>
    /// <param name="maxFailCount">最大失败次数</param>
    /// <param name="limitLoginMinutes">限制登陆分钟数</param>
    public LoginFailDto(string account
     //, int maxFailCount = 5
     //, int limitLoginMinutes = 30
     )
    {
        //this.MaxFailCount = maxFailCount;
        //this.LimitLoginMinute = limitLoginMinutes;

        this.Account = account;

        Ip = App.HttpContext.GetIpV4();
        if (string.IsNullOrWhiteSpace(Ip)) Ip = App.HttpContext.GetIpV4();
        FailCount = 1;//第一次，默认为1
    }

    /// <summary>
    /// 登陆账号
    /// </summary>
    public string Account { get; set; }

    /// <summary>
    /// 登陆IP地址
    /// </summary>
    public string Ip { get; set; }

    #region 账号限制

    /// <summary>
    /// 登陆师表次数
    /// </summary>
    public int FailCount { get; set; } = 1;

    ///// <summary>
    ///// 登陆最大失败次数
    ///// </summary>
    //public int MaxFailCount { get; set; } = 5;

    ///// <summary>
    ///// 限制登陆分钟数
    ///// </summary>
    //public int LimitLoginMinute { get; set; }

    /// <summary>
    /// 禁止登陆结束时间
    /// </summary>
    public DateTimeOffset? ExpireTime { get; set; }

    #endregion 账号限制

    //public void Fail()
    //{
    //    FailCount++;
    //    if (FailCount > MaxFailCount)
    //    {
    //        ProhibitLoginEndTime=DateTimeOffset.Now.AddMinutes(LimitLoginMinute);
    //        var ts = ProhibitLoginEndTime-DateTimeOffset.Now;
    //        throw Oops.Bah($"登陆错误次数超过 {MaxFailCount} 次，请 {ts.TotalMinutes} 分钟后再试！");
    //    }
    //}
}